/* GUI CONVERTED from adspmt.p (converter v1.76) Mon Apr 21 19:43:42 2003 */
/* adspmt.p - SALESPERSON MAINTENANCE                                   */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.10.1.7 $                                            */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 6.0      LAST MODIFIED: 04/29/91   BY: afs *D599**/
/* REVISION: 6.0      LAST MODIFIED: 08/09/91   BY: RAM *D820**/
/* REVISION: 7.0      LAST MODIFIED: 11/16/91   BY: pml *F048**/
/* REVISION: 7.0      LAST MODIFIED: 12/31/91   BY: pml *F080**/
/* REVISION: 7.0      LAST MODIFIED: 04/09/92   BY: tjs *F337**/
/* REVISION: 7.0      LAST MODIFIED: 06/30/92   BY: tjs *F698**/
/* REVISION: 7.3      LAST MODIFIED: 09/11/94   BY: slm *GM11**/
/* REVISION: 7.3      LAST MODIFIED: 11/06/94   BY: ame *GO16**/
/* REVISION: 8.5      LAST MODIFIED: 07/15/97   by: *H1BZ* Ajit Deodhar */
/* REVISION: 8.5      LAST MODIFIED: 07/17/97   by: *J1VT* Suresh Nayak */
/* REVISION: 8.5      LAST MODIFIED: 08/07/97   by: *J1YM* Seema Varma  */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.0      LAST MODIFIED: 03/10/99   by: *M0B3* Michael Amaladhas */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   by: *M0BD* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0KK* jyn               */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Revision: 1.10.1.6     BY: Katie Hilbert  DATE: 04/01/01 ECO: *P002* */
/* $Revision: 1.10.1.7 $    BY: Narathip W.    DATE: 04/17/03 ECO: *P0Q4* */
/* $Revision: eb2 sp3 $    BY: Joy Huang          DATE: 11/11/03  ECO: *HK-S-017*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* DISPLAY TITLE */
{mfdtitle.i "2+ "}
{cxcustom.i "ADSPMT.P"}

define variable del-yn like mfc_logical.
define variable spnbr like sp_addr.

/* DISPLAY SELECTION FORM */
{&ADSPMT-P-TAG1}

/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/

   sp_addr        colon 10
   ad_name        colon 10
   ad_line1       colon 10
   ad_line2       colon 10
   ad_line3       colon 10
   ad_city        colon 10
   ad_state
   ad_zip
   ad_format
   ad_country     colon 10
   ad_ctry          no-label
   ad_county      colon 56
   ad_attn        colon 10
   ad_attn2 label "[2]" colon 43
   ad_phone       colon 10
   ad_ext
   ad_phone2      label "[2]" colon 43
   ad_ext2
   ad_fax         colon 10
   ad_fax2        label "[2]" colon 43
   ad_date
 SKIP(.4)  /*GUI*/
with frame a  side-labels
   width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = (getFrameTitle("SALESPERSON_ADDRESS",28)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME


{&ADSPMT-P-TAG2}

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
sp_sort        colon 25
   sp_territory   colon 25
   sp_comm_pct    colon 25
 SKIP(.4)  /*GUI*/
with frame b  side-labels
   width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER.
 F-b-title = (getFrameTitle("SALESPERSON_DATA",24)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame b =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame b + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5. /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

do transaction on error undo, retry:
   find first adc_ctrl no-lock no-error.
   if not available adc_ctrl then create adc_ctrl.
   if recid(adc_ctrl) = -1 then .
end.

/* DISPLAY */

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   view frame a.
   view frame b.

   do transaction with frame a on error undo, leave mainloop:
/*GUI*/ if global-beam-me-up then undo, leave.

      view frame a.
      view frame b.

      prompt-for sp_mstr.sp_addr
      editing:

         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp.i sp_mstr sp_addr sp_addr sp_addr sp_addr sp_addr}

         if recno <> ? then do:
            find ad_mstr where ad_addr = sp_addr no-lock no-error.
            display sp_addr ad_name ad_line1 ad_line2 ad_line3 ad_city
               ad_state ad_zip ad_format ad_country
               ad_ctry
               ad_county
               ad_attn ad_phone ad_ext
               ad_attn2
               ad_fax ad_phone2 ad_ext2 ad_fax2
               ad_date.
            display sp_sort sp_territory sp_comm_pct
            with frame b.
         end.
      end.

      if input sp_addr = " " then do:
         {mfactrl.i spc_ctrl spc_nbr ad_mstr ad_addr spnbr}
         spnbr = string(integer(spnbr),"99999999").
      end.
      if input sp_addr <> "" then spnbr = input sp_addr.
      
/*hk-s-017*/        if (can-find(ls_mstr where input sp_addr = ls_addr no-lock)
	             or can-find(cm_mstr where input sp_addr = cm_addr no-lock)
	             or can-find(vd_mstr where input sp_addr = vd_addr no-lock))
	            then undo,retry.        
      
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*transaction */

   do transaction with frame a on endkey undo, next  mainloop:
/*GUI*/ if global-beam-me-up then undo, leave.

      /* ADD/MOD/DELETE  */

      find ad_mstr where ad_addr = input sp_addr no-error.
      if not available ad_mstr then do:
         create ad_mstr.
         assign
            ad_addr = spnbr
            ad_type = "slsprsn"
            ad_date = today
            ad_format = adc_format.
         if recid(ad_mstr) = -1 then .
      end.

      /* STORE MODIFY DATE AND USERID */
      ad_mod_date = today.
      ad_userid = global_userid.

      find sp_mstr where sp_addr = ad_addr no-error.
      if not available sp_mstr then do:
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
         create sp_mstr.
         assign sp_addr = spnbr.
         if recid(sp_mstr) = -1 then .

         create ls_mstr.
         assign
            ls_addr = sp_addr
            ls_type = "slsprsn".
         if recid(ls_mstr) = -1 then .
      end.

      display sp_sort sp_territory sp_comm_pct with frame b.

      del-yn = no.
      recno = recid(sp_mstr).

      ststatus = stline[2].
      status input ststatus.

      display
         sp_addr
         ad_name ad_line1 ad_line2 ad_line3 ad_city ad_state ad_zip ad_format
         ad_country
         ad_ctry
         ad_county ad_attn ad_phone ad_ext ad_fax ad_phone2 ad_ext2 ad_fax2
         ad_attn2
         ad_date.
      set1:
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         set ad_name ad_line1 ad_line2 ad_line3
            ad_city ad_state ad_zip ad_format
            ad_ctry
            ad_county
            ad_attn
            ad_phone
            ad_ext
            ad_fax
            ad_attn2
            ad_phone2
            ad_ext2
            ad_fax2
            ad_date go-on (F5 CTRL-D).

         if ad_format <> 0 then do:
            find first code_mstr where code_fldname = "ad_format"
               and code_value = string(ad_format) no-lock no-error.
            if not available code_mstr then do:
               /* Code does not exist in generalized codes */
               {pxmsg.i &MSGNUM=716 &ERRORLEVEL=4}
               next-prompt ad_format.
               undo.
            end.
         end.

         /* VALIDATE COUNTRY CODE */
         if not {gpctry.v ad_ctry ""no""} then do:
            {pxmsg.i &MSGNUM=861 &ERRORLEVEL=3} /* COUNTRY CODE DOES NOT EXIST */
            next-prompt ad_ctry with frame a.
            undo set1, retry.
         end. /* IF NOT {GPCTRY.V AD_CTRY ""NO""} */
         else do:
            find ctry_mstr where ctry_ctry_code = ad_ctry no-lock no-error.
            if available ctry_mstr then do:
               ad_country = ctry_country.
               display ad_country with frame a.
            end. /* IF AVAILABLE CTRY_MSTR */
         end. /* ELSE DO */

         /* DELETE */
         if lastkey = keycode("F5") or
            lastkey = keycode("CTRL-D")
         then do:
            del-yn = yes.
            {mfmsg01.i 11 1 del-yn}
            if del-yn = no then undo set1.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

      if del-yn then do:

         /* CHECK IF SALESPERSONS SALES ANALYSIS */
         if can-find(first sph_hist where sph_slspsn1 = sp_addr) then do:
            find last  sph_hist where sph_slspsn1 = sp_addr no-lock.
            {pxmsg.i &MSGNUM=639 &ERRORLEVEL=3}
            next mainloop.
         end.

         {adlsdl.i ad_mstr "slsprsn"} /* delete user maintained ls_mstr */

         /* DELETE LIST MASTER */
         find ls_mstr where ls_addr = sp_addr and ls_type = "slsprsn"
            exclusive-lock no-error.
         if available ls_mstr then delete ls_mstr.

         /* DELETE ADDRESS MASTER */
         find first ls_mstr where ls_addr = sp_addr no-error.
         if not available ls_mstr then delete ad_mstr.

         /* DELETE COMMISSION DETAIL */
         for each spd_det where spd_addr = sp_addr exclusive-lock.
            delete spd_det.
         end.

         /* DELETE SALESPERSON  MASTER */
         delete sp_mstr.
         clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
         clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
         del-yn = no.
         {pxmsg.i &MSGNUM=22 &ERRORLEVEL=1}
         next mainloop.

      end.
      status input.

      if sp_sort = "" then sp_sort = ad_name.
      if ad_sort = "" then ad_sort = ad_name.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.

   /* END LOOP A  */

   loopb:
   do transaction on endkey undo, next mainloop:
/*GUI*/ if global-beam-me-up then undo, leave.


      ststatus = stline[3].
      status input ststatus.
      if sp_sort = "" then sp_sort = ad_name.
      update sp_sort sp_territory sp_comm_pct with frame b.
      ad_sort = sp_sort.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.

   /*END LOOP B */

end.
/*GUI*/ if global-beam-me-up then undo, leave.

/* END MAIN LOOP */
status input.
